package it.polimi.swKnights.SWIMv2.servlets.messages;

import it.polimi.swKnights.SWIMv2.ejb.messages.MessageHandlerBeanRemote;
import it.polimi.swKnights.SWIMv2.servlets.SwimServlet;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AjaxUnreadCount
 */
public class AjaxUnreadCount extends SwimServlet
{
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{

		PrintWriter out = response.getWriter();

		String userName = (String) request.getSession()
				.getAttribute("userName");
		String password = (String) request.getSession()
				.getAttribute("password");

		MessageHandlerBeanRemote userFinderBean = this
				.lookUp(MessageHandlerBeanRemote.class);

		int howManyUnred = userFinderBean.getMessagesCountFromUser(userName,
				password);
		
		out.println("" + howManyUnred);

	}

}
